<?php
namespace app\api\controller;
use think\Controller;
use think\Db;

class Index extends Controller {
    //根据客户手机获取客服信息
    public function getActions(){
    	
 		$data = Db::name('activity')
            ->select();

    }

    //返回参数,并记录日志
    public function back($msg,$code,$data=[]){
        $returndata['code'] = $code;
        $returndata['msg'] = $msg;
        $returndata['data'] = $data;
        Db::name('apilog')->insert(['url'=>request()->baseUrl(),'req'=>json_encode(array_filter(request()->param())),'back'=>json_encode($data),'create_time'=>now(),'code'=>$code,'msg'=>$msg,'ip'=>request()->ip()]);
        exit(json_encode($returndata));
    }

    public function outsql(){

        $sql = "SELECT v.*,arct.typename as arcname,count(v.tid) as tidsum
                FROM `#@__xcx_visitor` v 
                JOIN `#@__arctype` arct ON arct.id = v.tid 
                GROUP BY v.tid 
                ORDER BY v.tid DESC";
        $currMonth = date('m');
        $month0 = strtotime(date("Y-m-01 00:00:00"));
        $month1 = strtotime(date("Y-".($currMonth-1)."-01 00:00:00"));
        $month2 = strtotime(date("Y-".($currMonth-2)."-01 00:00:00"));

        $data = Db::name('arctype')
            ->alias('a')
            ->join('xcx_visitor v','a.id = v.tid')
//            ->group('v.tid')
            ->field('v.id,v.tid,v.create_time,a.typename')
            ->order('v.tid desc')
            ->select();
        exit(json_encode($data));
        return count($data);

    }
}
